package com.ruoyi.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.BusDeviceCompanies;
import com.ruoyi.business.service.IBusDeviceCompaniesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 入驻企业Controller
 * 
 * @author ruoyi
 * @date 2023-08-04
 */
@RestController
@RequestMapping("/device/companies")
@Api(tags = "设施农业-入驻企业")
public class BusDeviceCompaniesController extends BaseController
{
    @Autowired
    private IBusDeviceCompaniesService busDeviceCompaniesService;

    /**
     * 查询入驻企业列表
     */
    @GetMapping("/list")
    @ApiOperation("列表数据")
    public TableDataInfo list(BusDeviceCompanies busDeviceCompanies)
    {
        startPage();
        List<BusDeviceCompanies> list = busDeviceCompaniesService.selectBusDeviceCompaniesList(busDeviceCompanies);
        return getDataTable(list);
    }

    /**
     * 导出入驻企业列表
     */
    @PreAuthorize("@ss.hasPermi('device:companies:export')")
    @Log(title = "入驻企业", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusDeviceCompanies busDeviceCompanies)
    {
        List<BusDeviceCompanies> list = busDeviceCompaniesService.selectBusDeviceCompaniesList(busDeviceCompanies);
        ExcelUtil<BusDeviceCompanies> util = new ExcelUtil<BusDeviceCompanies>(BusDeviceCompanies.class);
        util.exportExcel(response, list, "入驻企业数据");
    }

    /**
     * 获取入驻企业详细信息
     */
    @PreAuthorize("@ss.hasPermi('device:companies:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(busDeviceCompaniesService.selectBusDeviceCompaniesById(id));
    }

    /**
     * 新增入驻企业
     */
    @PreAuthorize("@ss.hasPermi('device:companies:add')")
    @Log(title = "入驻企业", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusDeviceCompanies busDeviceCompanies)
    {
        return toAjax(busDeviceCompaniesService.insertBusDeviceCompanies(busDeviceCompanies));
    }

    /**
     * 修改入驻企业
     */
    @PreAuthorize("@ss.hasPermi('device:companies:edit')")
    @Log(title = "入驻企业", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusDeviceCompanies busDeviceCompanies)
    {
        return toAjax(busDeviceCompaniesService.updateBusDeviceCompanies(busDeviceCompanies));
    }

    /**
     * 删除入驻企业
     */
    @PreAuthorize("@ss.hasPermi('device:companies:remove')")
    @Log(title = "入驻企业", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(busDeviceCompaniesService.deleteBusDeviceCompaniesByIds(ids));
    }
}
